package com.emperor.productlog.logic;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.emperor.category.logic.Category;
import com.emperor.core.logic.BizModelBase;
import com.emperor.product.logic.Product;
import com.emperor.receipt.logic.Receipt;
import com.emperor.transaction.logic.Transaction;
import com.emperor.util.DateFormatter;

public class ProductLogModel extends BizModelBase implements ProductLog {

	private Long id;
	private String actionname;
	private Product product;
	private Transaction transaction;
	private Category category;
	private String name;
	private String desc;
	private String sku;
	private Double quantity;
	private Double xquantity;
	private Double weight;
	private String weightuom;
	private Double price;
	private Double discount;
	private Integer version;
	private String status;
	private Long crtby;
	private Date crtdate;
	private Long updby;
	private Date upddate;
	private String invoiceno;
	private String color;
	private Double cost;
	
	private SimpleDateFormat sdf = new SimpleDateFormat(DateFormatter.YYYYMMDD);
	
	public Long getId() {
		return id;
	}

	public void setId(Object id) {
		if (id != null) {
			if (id instanceof Long) {
				this.id = (Long) id;
			} else {
				try {
					this.id = new Long(id.toString());
				} catch (Exception e) {
				}
			}
		}
	}

	public String getActionname() {
		return actionname;
	}

	public void setActionname(Object actionname) {
		if (actionname != null) {
			if (actionname instanceof String) {
				this.actionname = (String) actionname;
			} else {
				try {
					this.actionname = actionname.toString();
				} catch (Exception e) {
				}
			}
		}
	}

	public Product getProduct() {
		return product;
	}

	public void setProduct(Object product) {
		if (product != null) {
			if (product instanceof Product) {
				this.product = (Product) product;
			}
		}
	}

	public Category getCategory() {
		return category;
	}

	public void setCategory(Object category) {
		if (category != null) {
			if (category instanceof Category) {
				this.category = (Category) category;
			}
		}
	}

	public String getName() {
		return name;
	}

	public void setName(Object name) {
		if (name != null) {
			if (name instanceof String) {
				this.name = (String) name;
			} else {
				try {
					this.name = name.toString();
				} catch (Exception e) {
				}
			}
		}
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(Object desc) {
		if (desc != null) {
			if (desc instanceof String) {
				this.desc = (String) desc;
			} else {
				try {
					this.desc = desc.toString();
				} catch (Exception e) {
				}
			}
		}
	}

	public String getSku() {
		return sku;
	}

	public void setSku(Object sku) {
		if (sku != null) {
			if (sku instanceof String) {
				this.sku = (String) sku;
			} else {
				try {
					this.sku = sku.toString();
				} catch (Exception e) {
				}
			}
		}
	}

	public Double getQuantity() {
		return quantity;
	}

	public void setQuantity(Object quantity) {
		if (quantity != null) {
			if (quantity instanceof Double) {
				this.quantity = (Double) quantity;
			} else {
				try {
					this.quantity = new Double(quantity.toString());
				} catch (Exception e) {
				}
			}
		}
	}

	public Double getPrice() {
		return price;
	}

	public void setPrice(Object price) {
		if (price != null) {
			if (price instanceof Double) {
				this.price = (Double) price;
			} else {
				try {
					this.price = new Double(price.toString());
				} catch (Exception e) {
				}
			}
		}
	}

	public Double getDiscount() {
		return discount;
	}

	public void setDiscount(Object discount) {
		if (discount != null) {
			if (discount instanceof Double) {
				this.discount = (Double) discount;
			} else {
				try {
					this.discount = new Double(discount.toString());
				} catch (Exception e) {
				}
			}
		}
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		if (status != null) {
			if (status instanceof String) {
				this.status = (String) status;
			} else {
				try {
					this.status = status.toString();
				} catch (Exception e) {
				}
			}
		}
	}

	public Long getCrtby() {
		return crtby;
	}

	public void setCrtby(Object crtby) {
		if (crtby != null) {
			if (crtby instanceof Long) {
				this.crtby = (Long) crtby;
			} else {
				try {
					this.crtby = new Long(crtby.toString());
				} catch (Exception e) {
				}
			}
		}
	}

	public Date getCrtdate() {
		return crtdate;
	}

	public void setCrtdate(Object crtdate) {
		if (crtdate != null) {
			if (crtdate instanceof Date) {
				this.crtdate = (Date) crtdate;
			} else {
				try {
					this.crtdate = sdf.parse(crtdate.toString());
				} catch (Exception e) {
				}
			}
		}
	}

	public Long getUpdby() {
		return updby;
	}

	public void setUpdby(Object updby) {
		if (updby != null) {
			if (updby instanceof Long) {
				this.updby = (Long) updby;
			} else {
				try {
					this.updby = new Long(updby.toString());
				} catch (Exception e) {
				}
			}
		}
	}

	public Date getUpddate() {
		return upddate;
	}

	public void setUpddate(Object upddate) {
		if (upddate != null) {
			if (upddate instanceof Date) {
				this.upddate = (Date) upddate;
			} else {
				try {
					this.upddate = sdf.parse(upddate.toString());
				} catch (Exception e) {
				}
			}
		}
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Object version) {
		if (version != null) {
			if (version instanceof Integer) {
				this.version = (Integer) version;
			} else {
				try {
					this.version = new Integer(version.toString());
				} catch (Exception e) {
				}
			}
		}
	}

	@Override
	public List<String> getFieldNames() {
		List<String> fieldNames = new ArrayList<String>();
		
		fieldNames.add(FLD_ID);
		fieldNames.add(FLD_ACTIONNAME);
		fieldNames.add(FLD_PRODUCT);
		fieldNames.add(FLD_TRANSACTION);
		fieldNames.add(FLD_CATEGORY);
		fieldNames.add(FLD_NAME);
		fieldNames.add(FLD_DESC);
		fieldNames.add(FLD_SKU);
		fieldNames.add(FLD_QUANTITY);
		fieldNames.add(FLD_XQUANTITY);
		fieldNames.add(FLD_WEIGHT);
		fieldNames.add(FLD_WEIGHTUOM);
		fieldNames.add(FLD_PRICE);
		fieldNames.add(FLD_DISCOUNT);
		fieldNames.add(FLD_VERSION);
		fieldNames.add(FLD_STATUS);
		fieldNames.add(FLD_INVOICENO);
		fieldNames.add(FLD_COLOR);
		fieldNames.add(FLD_COST);

		fieldNames.add(FLD_CRTBY);
		fieldNames.add(FLD_CRTDATE);
		fieldNames.add(FLD_UPDBY);
		fieldNames.add(FLD_UPDDATE);
		
		return fieldNames;
	}

	@Override
	public void copyProduct(Product product) {
		if (product != null) {
			
			this.setProduct(product);
			
			this.setCategory(product.getCategory());
			this.setDesc(product.getDesc());
			this.setDiscount(product.getDiscount());
			this.setName(product.getName());
			this.setPrice(product.getPrice());
			this.setQuantity(product.getQuantity());
			this.setWeight(product.getWeight());
			this.setWeightuom(product.getWeightuom());
			this.setSku(product.getSku());
			this.setInvoiceno(product.getInvoiceno());
			this.setColor(product.getColor());
			this.setCost(product.getCost());
		}
	}

	public Transaction getTransaction() {
		return transaction;
	}

	public void setTransaction(Object transaction) {
		if (transaction != null) {
			if (transaction instanceof Transaction) {
				this.transaction = (Transaction) transaction;
			}
		}
	}

	public Double getXquantity() {
		return xquantity;
	}

	public void setXquantity(Object xquantity) {
		if (xquantity != null) {
			if (xquantity instanceof Double) {
				this.xquantity = (Double) xquantity;
			} else {
				try {
					this.xquantity = new Double(xquantity.toString());
				} catch (Exception e) {
				}
			}
		}
	}

	public Double getWeight() {
		return weight;
	}

	public void setWeight(Object weight) {
		if (weight != null) {
			if (weight instanceof Double) {
				this.weight = (Double) weight;
			} else {
				try {
					this.weight = new Double(weight.toString());
				} catch (Exception e) {
				}
			}
		}
	}

	public String getWeightuom() {
		return weightuom;
	}

	public void setWeightuom(Object weightuom) {
		if (weightuom != null) {
			if (weightuom instanceof String) {
				this.weightuom = (String) weightuom;
			} else {
				try {
					this.weightuom = weightuom.toString();
				} catch (Exception e) {
				}
			}
		}
	}

	public String getInvoiceno() {
		return invoiceno;
	}

	public void setInvoiceno(Object invoiceno) {
		if (invoiceno != null) {
			if (invoiceno instanceof String) {
				this.invoiceno = (String) invoiceno;
			} else {
				try {
					this.invoiceno = invoiceno.toString();
				} catch (Exception e) {
				}
			}
		}
	}

	public String getColor() {
		return color;
	}

	public void setColor(Object color) {
		if (color != null) {
			if (color instanceof String) {
				this.color = (String) color;
			} else {
				try {
					this.color = color.toString();
				} catch (Exception e) {
				}
			}
		}
	}

	public Double getCost() {
		return cost;
	}

	public void setCost(Object cost) {
		if (cost != null) {
			if (cost instanceof Double) {
				this.cost = (Double) cost;
			} else {
				try {
					this.cost = new Double(cost.toString());
				} catch (Exception e) {
				}
			}
		}
	}
	
	
	
}
